package com.cloudz.iptv.component;

import android.content.Context;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudz.iptv.R;

/**
 * @File Name: com.cloudz.iptv.component
 * @Author: YJ //作者及
 * @Date: 2018-12-13 14:03//完成日期
 * @Description: // 描述
 * @Version: v0.0.1 // 版本信息
 * @Function List: // 主要函数及其功能
 * @Others: // 其它内容的说明
 * @History: // 历史修改记录
 */
public class CustomImageButton extends LinearLayout
{
    private ImageView imageView;

    private TextView textView;

    public CustomImageButton(Context context, AttributeSet attrs, int defStyle)
    {
        super(context);


        // 0 处理控件
        setClickable(false);

        setFocusable(false);

        setGravity(Gravity.CENTER_VERTICAL);

        // 垂直居中
        setOrientation(LinearLayout.VERTICAL);

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

        //layoutParams.gravity = Gravity.CENTER_VERTICAL;

        setLayoutParams(layoutParams);

        // 1 处理图片
        imageView = new ImageView(context);

        LinearLayout.LayoutParams imageViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        //设置图片布局居中
        imageViewLayoutParams.gravity = Gravity.CENTER;
//        imageViewLayoutParams.topMargin = 10;

        imageView.setImageResource(R.drawable.ic_launcher_background);

        imageView.setLayoutParams(imageViewLayoutParams);

        // 2 处理文字

        textView = new TextView(context);

        //设置文字水平居中
        textView.setGravity(Gravity.CENTER_HORIZONTAL);

        textView.setPadding(0, 0, 0, 0);


        textView.setLayoutParams(imageViewLayoutParams);

        addView(imageView);

        addView(textView);
    }

    public ImageView getImageView()
    {
        return imageView;
    }

    public TextView getTextView()
    {
        return textView;
    }

    public void setImageResource(@DrawableRes int resId)
    {
        imageView.setImageResource(resId);
    }
}
